#pragma once

#include "SortedHeaderCtrl.h"

class ListCtrlTest : public CListCtrl
{
	DECLARE_DYNAMIC(ListCtrlTest)

public:
	ListCtrlTest();
	virtual ~ListCtrlTest();

	CImageList* SetImageList(CImageList* pImageList, int nImageListType = TVSIL_NORMAL)
	{ 
		return CListCtrl::SetImageList(pImageList,nImageListType); 
	};

	BOOL AddColumn(
		LPCTSTR strItem,int nItem,int nSubItem = -1,
		int nMask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
		int nFmt = LVCFMT_LEFT);

	BOOL DySetItem(_In_ int nItem, int nSubItem, LPCTSTR strItem, int nImageIndex = -1);
	void SetCurSel(int id);
	int GetCurSel();

	void AddToItem(int row, int col, CString cs, int nImageIndex = -1);
    static int CALLBACK CallbackCompareItems(LPARAM lParam1, LPARAM lParam2, LPARAM lParam3);

	bool IsColumnCheck(int colnumn);

	void SetEnableEditLabel(BOOL bEditLabel)
	{
		m_InPlaceListDatas.RemoveAll();
		m_bEditLabel = bEditLabel;
	};

protected:
	DECLARE_MESSAGE_MAP()
	BOOL AddItem(int nItem,int nSubItem,LPCTSTR strItem,int nImageIndex = -1);

	CEdit* EditSubLabel(int nItem, int nCol);
	CComboBox* ShowInPlaceList(int nItem, int nCol, CStringList &lstItems, int nSel);

	bool HitTestRowCol(CPoint& point, int& iRow, int& iColumn)const;

	BOOL m_bEditLabel;

	CArray<InPlaceListData,InPlaceListData&> m_InPlaceListDatas;

    BOOL m_Sorting;
    CSortedHeaderCtrl m_HeaderCtrl;

	vector<CEdit*> m_pEdits;
	CEdit* m_pEdit;

	BOOL m_bHasBitMap;

protected:
    virtual void PreSubclassWindow();

	virtual void SetBitmap();
public:

	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult);
    afx_msg void OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult);

	int GetTrueColumnWidth(int nCurrentPosition)const;
	void SetInPlaceList(int nCol, vector<CString> strs);
	void SetInPlaceEdit(int nCol);
	void SetInPlaceCheck(int nCol);

    void SortColumn(int nCol, BOOL bAsc);
    int GetSortedColumn();
    static bool IsCStringDigit(CString cs);
    BOOL IsAscSorted();
    static void GetStringTailNumHeadString(CString cs, CString &csHead, int &num);
    void SetEnableSorting(BOOL bSort);
	int GetItemIconId(int item, int icolumn);
	int GetColumnInitImageIndex(int column);

	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	afx_msg void OnDestroy();

	CImageList* m_pImageList;
	CArray<int, int&> m_iColumStartPos;

	void CalColumnStartPos();
};
